from SPARQLWrapper import SPARQLWrapper, JSON
import pandas as pd
import sparql_dataframe
import geopandas as gpd
from shapely import wkt
import matplotlib.pyplot as plt
import folium
import VizKG.visualize as vkgAddresses in Paris
Retrieving and visualising the addresses of artists that expose in Paris
endpoint = "http://localhost:3030/Basart/sparql"For retrieving from Basart the addresses we filter, with a SPARQL query, all artists that have exposed Paris, and we retrieve their address (as given in the catalogues)
SPARQL
q ="""
PREFIX frbroo: <http://iflastandards.info/ns/fr/frbr/frbroo/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX crmdig: <http://www.ics.forth.gr/isl/CRMdig/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX aat: <http://vocab.getty.edu/aat/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX frbroo: <http://iflastandards.info/ns/fr/frbr/frbroo/>
# Addresses in Paris
SELECT DISTINCT ?personLabel ?address ?address_label ?coordinates WHERE {
VALUES ?paris {<https://visualcontagions.unige.ch/resources/city/33661>}
?person crm:P14i_performed ?pursuit ;
rdfs:label ?personLabel .
?pursuit a frbroo:F51_Pursuit ;
crm:P7_took_place_at ?address .
?address a crm:E53_Place;
rdfs:label ?address_label ;
crm:P168_place_is_defined_by ?coordinates ;
crm:P89_falls_within ?paris .
FILTER NOT EXISTS {
VALUES ?trash {<https://visualcontagions.unige.ch/resources/address/5605> } .
?pursuit crm:P7_took_place_at ?trash .
}
}
"""df = sparql_dataframe.get(endpoint, q)Once done we quickly compute how many people share an address
df['counts'] = df.groupby(['address_label'])['personLabel'].transform('count')a, b = 1, 10
x, y = df.counts.min(), df.counts.max()
df['SIZE'] = (df.counts - x) / (y - x) * (b - a) + adf| personLabel | address | address_label | coordinates | counts | SIZE | |
|---|---|---|---|---|---|---|
| 0 | Renée Blum | https://visualcontagions.unige.ch/resources/ad... | 37 rue Froidevaux | POINT(2.3278893 48.8358163) | 7 | 2.631579 |
| 1 | René Pottier | https://visualcontagions.unige.ch/resources/ad... | 37 rue Froidevaux | POINT(2.3278893 48.8358163) | 7 | 2.631579 |
| 2 | Marie Vassilieff | https://visualcontagions.unige.ch/resources/ad... | 37 rue Froidevaux | POINT(2.3278893 48.8358163) | 7 | 2.631579 |
| 3 | Walter-René Fuerst | https://visualcontagions.unige.ch/resources/ad... | 37 rue Froidevaux | POINT(2.3278893 48.8358163) | 7 | 2.631579 |
| 4 | Claire Fargue | https://visualcontagions.unige.ch/resources/ad... | 37 rue Froidevaux | POINT(2.3278893 48.8358163) | 7 | 2.631579 |
| ... | ... | ... | ... | ... | ... | ... |
| 8853 | Zénaïde TOLSTOI | https://visualcontagions.unige.ch/resources/ad... | 6 rue Guy-de-Maupassant | POINT(2.2733469 48.8628883) | 1 | 2.000000 |
| 8854 | Bénoni AURAN | https://visualcontagions.unige.ch/resources/ad... | 32 rue de la Santé | POINT(2.3416085 48.8355621) | 6 | 2.526316 |
| 8855 | Marcel BACH | https://visualcontagions.unige.ch/resources/ad... | 7 et 9 rue Alain-Chartier | POINT(2.2949238 48.8385904) | 1 | 2.000000 |
| 8856 | Tristan L. Klingsor | https://visualcontagions.unige.ch/resources/ad... | 28 avenue René Coty | POINT(2.3342423 48.828786) | 1 | 2.000000 |
| 8857 | Félix BAUDIN | https://visualcontagions.unige.ch/resources/ad... | 21 rue Berthe | POINT(2.3379702 48.8861244) | 4 | 2.315789 |
8858 rows × 6 columns
And we plot this information on a map of Paris
df['geometry'] = df.coordinates.apply(wkt.loads)
df.drop('coordinates', axis=1, inplace=True)
gdf = gpd.GeoDataFrame(df, geometry='geometry')
geo_df_list = [[point.xy[1][0], point.xy[0][0]] for point in gdf.geometry]
gdf['lon'] = gdf['geometry'].x
gdf['lat'] = gdf['geometry'].y
geo_df_list = [[point.xy[1][0], point.xy[0][0]] for point in gdf.geometry]map = folium.Map(tiles="cartodbpositron", location=[48.8598854,2.3427464], zoom_start=13)
i = 0
for coordinates in geo_df_list:
# Place the markers with the popup labels and data
map.add_child(
folium.CircleMarker(
location=coordinates,
radius=2,
color="red", weight=1, fill_color="red", fill_opacity=0.7,
popup=
"Artist: " + str(gdf.personLabel[i]) + "<br>"
+ "Address: " + str(gdf.address_label[i]),
)
)
i = i + 1mapMake this Notebook Trusted to load map: File -> Trust Notebook